#
# tcore.py
#
#
# PyEMOF: An EMOF support for Python
#
# Copyright (C) 2004, 2007 Raphael Marvie 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# http://www.fsf.org/licensing/licenses/gpl.html
#
# Author contact: raphael.marvie@lifl.fr
#
# Modified and adapted to conform with ECORE 2.0 by brenomachado@gmail.com



'''
Templates for the generation of EMOF repositories from the definition
of a EMOF compliant model.
'''

__author__  = 'Raphael Marvie <raphael.marvie@lifl.fr> / Breno Batista Machado <brenomachado@gmail.com>'
__date__    = '2008-03-15'
__version__ = '0.7.0'

class tstr:
    pass

class tmpl:
    
    file_header = """# -*- coding: utf-8 -*-
#
# %(name)s.py

%(modules_imports)s
        
"""

    import_template = """import %(module)s
"""

    multiple_attribute = """
    def get_%(name)s(self):
        return self._%(name)s
    def add_%(name)s(self, val):
        self._%(name)s.append(val)
    %(name)s = property(get_%(name)s)
"""

    readonly_attribute = """
    def get_%(name)s(self):
        return self._%(name)s
    %(name)s = property(get_%(name)s)
"""

    repository_class = """

class Repository(object):

    def __init__(self):
        super(Repository, self).__init__()
"""
    
    repository_attr = """        self._%(name)s = %(value)s
"""

    repository_attr_enum = """        self._%(name)s = %(module)s%(name)s
"""

    repository_attr_other_rep = """        self._%(name)s = %(module)sRepository()
"""

    repository_prop = multiple_attribute
    
    repository_prop_enum = readonly_attribute
    
    repository_prop_other_rep = readonly_attribute
    
    factory_class = """

class Factory(object):

    def __init__(self, repository):
        super(Factory, self).__init__()
        self._repository = repository
"""
    factory_attr_other_fact = """        self._%(name)s = %(module)sFactory(self._repository.%(name)s)
"""

    factory_method = """
    def create_%(name)s(self):
        o = %(module)s%(name)s()
        self._repository.%(name)s.append(o)
        return o
"""

    factory_prop_other_fact = readonly_attribute

    file_footer = """
# eof
"""
